package com.xcity.record;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;

import com.xcity.merge.MergeUtil;

public class Item extends BaseRecord {
	public static String SQL_PARA = "id, itemId, ownerId, bagId, pos, count, createTime, attributes";
	
	public static String COUNT_SQL = "select count(id) from item {0}";
	public static String SELECT_LIMIT = "select * from item {2} limit {0},{1}";
	public static String CONDITION = "WHERE item.ownerId not IN (SELECT player.id FROM player WHERE player.vipLvl = {0} AND player.`level` < {1} AND player.lastLoginTime < \"{2}\")";
	
	protected long id;
	protected int itemId;
	protected long ownerId;
	protected byte bagId;
	protected int pos;
	protected int count;
	protected Date createTime;
	protected String attributes;
	
	@Override
	public void load(ResultSet rs) throws SQLException {
		this.id = rs.getLong(1);
		this.itemId = rs.getInt(2);
		this.ownerId = rs.getLong(3);
		this.bagId = rs.getByte(4);
		this.pos = rs.getInt(5);
		this.count = rs.getInt(6);
		this.createTime = rs.getTimestamp(7);
		this.attributes = rs.getString(8);
	}

	@Override
	public String getColumnNames() {
		return SQL_PARA;
	}

	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		sb.append(MergeUtil.toSqlString(id));
		sb.append(", ");
		sb.append(MergeUtil.toSqlString(itemId));
		sb.append(", ");
		sb.append(MergeUtil.toSqlString(ownerId));
		sb.append(", ");
		sb.append(MergeUtil.toSqlString(bagId));
		sb.append(", ");
		sb.append(MergeUtil.toSqlString(pos));
		sb.append(", ");
		sb.append(MergeUtil.toSqlString(count));
		sb.append(", ");
		sb.append(MergeUtil.toDateString(createTime));
		sb.append(", ");
		sb.append(MergeUtil.toSqlString(attributes));
		return sb.toString();
	}

}
